package com.mjh.controller;

import com.github.pagehelper.PageInfo;
import com.mjh.bean.Activity;
import com.mjh.bean.User;
import com.mjh.model.R;
import com.mjh.query.ActivityQueryCondition;
import com.mjh.service.ActivityService;
import com.mjh.vo.ActivityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *市场活动
 */
@RestController
@RequestMapping("/api/activity")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    /**
     * 分页查询市场活动
     * @return
     */
    @GetMapping("/page")
    public R<PageInfo<ActivityVo>> pageInfo(ActivityQueryCondition activityQueryCondition){
        PageInfo<ActivityVo> pageInfo =  activityService.queryActivityListPage(activityQueryCondition);
        return R.OK(pageInfo);
    }
    /**
     * 添加市场活动
     * @return
     */
    @PostMapping("/add")
    public R<String> saveActivity(@RequestBody Activity activity){
        Boolean result = activityService.saveActivity(activity);
        return R.HANDLER(result);
    }
    /**
     * 根据id查询市场活动 修改回显
     * @return
     */
    @GetMapping("/info/{id}")
    public R<ActivityVo> queryActivityById(@PathVariable("id") Integer id){
        ActivityVo activityVo = activityService.queryActivityById(id);
        return R.OK(activityVo);
    }
    /**
     * 修改市场活动
     * @return
     */
    @PutMapping
    public R<String> modifyActivity(@RequestBody Activity activity){
        Boolean result = activityService.modifyActivity(activity);
        return R.HANDLER(result);
    }
    /**
     * 根据id查询市场活动详情
     * @return
     */
    @GetMapping("/detail/{id}")
    public R<ActivityVo> queryActivityDetailById(@PathVariable("id") Integer id){
        ActivityVo activityVo = activityService.queryActivityDetailById(id);
        return R.OK(activityVo);
    }
    /**
     * 根据id删除市场活动
     * @return
     */
    @DeleteMapping("/{id}")
    public R<String> removeActivity(@PathVariable("id") Integer id){
        Boolean result = activityService.removeActivity(id);
        return R.HANDLER(result);
    }
    /**
     * 批量删除市场活动
     * @return
     */
    @DeleteMapping("/batch/{ids}")
    public R<String> removeActivityBatch(@PathVariable List<Integer> ids){
        Boolean result = activityService.removeActivityBatch(ids);
        return R.HANDLER(result);
    }
    /**
     * 查询市场活动列表
     * @return
     */
    @GetMapping("/list")
    public R<List<Activity>> queryActivityList(){
        List<Activity> list = activityService.queryActivityList();
        return R.OK(list);
    }

}
